﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	CamlQueryBuilderItem.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

namespace Smart.Common.Entities
{
	/// <summary>
	/// QueryBuilder Query Item
	/// </summary>
	public abstract class CamlQueryBuilderItem<TExecutorType> : IQueryBuilderItem<TExecutorType>
		where TExecutorType : class
	{
		/// <summary>
		/// Query Builder
		/// </summary>
		public IQueryBuilder<TExecutorType> Query { get; set; }

		/// <summary>
		/// Return to QueryBuilder Where
		/// </summary>
		public IQueryBuilderWhere<TExecutorType> Where
		{
			get { return Query.Where; }
		}

		/// <summary>
		/// Return to QueryBuilder OrderBy
		/// </summary>
		public IQueryBuilderOrderBy<TExecutorType> OrderBy
		{
			get { return Query.OrderBy; }
		}

		/// <summary>
		/// Return to QueryBuilder GroupBy
		/// </summary>
		public IQueryBuilderGroupBy<TExecutorType> GroupBy
		{
			get { return Query.GroupBy; }
		}

		/// <summary>
		/// Return to QueryBuilder Executor
		/// </summary>
		public TExecutorType Executor
		{
			get { return Query.Executor; }
		}

		/// <summary>
		/// Immediate Group
		/// </summary>
		public CamlQueryBuilderItemGroup<TExecutorType> Group { get; set; }

		/// <summary>
		/// Return casted query executor
		/// </summary>
		public TMyExecutorType GetExecutor<TMyExecutorType>() where TMyExecutorType : TExecutorType
		{
			return (TMyExecutorType)Executor;
		}

		/// <summary>
		/// Operator
		/// </summary>
		public string Op { get; set; }

		/// <summary>
		/// QueryBuilder Query Item
		/// </summary>
		/// <param name="op">Operator</param>
		protected CamlQueryBuilderItem(string op)
		{
			this.Op = op;
		}

		/// <summary>
		/// Format CAML statement
		/// </summary>
		public abstract string FormatQuery();

		/// <summary>
		/// Return Cache code (hash of cache-dependent parameters)
		/// </summary>
		public abstract int GetCacheCode();
	}
}